package com.cedarhd.finance.bl.domain.service;

import com.cedarhd.finance.bl.domain.entity.Student;
import com.cedarhd.finance.bl.domain.repository.StudentRepository;
import com.cedarhd.finance.bl.dto.StudentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Evan
 * @date 2018/3/5
 */
@Service
public class StudentService {

    @Autowired
    private StudentRepository studentRepository;

    public StudentRepository getRepository(){
        return studentRepository;
    }

    /**
     * 新增学生
     * @param dto
     * @return
     */
    public Student add(StudentDTO dto){
        Student student = new Student();
        student.setAge(dto.getAge());
        student.setEffective(dto.getEffective());
        student.setStudentName(dto.getStudtntName());
        return studentRepository.saveAndFlush(student);
    }

    /**
     * 这里可以做封装处理，现在简单直接list返回
     * @param studentPage
     * @return
     */
    public List<Student> coverStudentDTO(Page<Student> studentPage){
        List<Student> result = new ArrayList<>();
        for(Student student : studentPage){
            result.add(student);
        }
        return result;
    }
}
